<template>
  <el-scrollbar style='height:100%' class="menulist">
    <!-- 一般状态下显示 -->
    <el-menu :default-openeds="openeds" v-if="show == 'domain'">
      <el-submenu index="company">
        <!-- <template slot="title"> -->
          <!-- <span class="over-ellipsis domainName-over-ellipsis" :title="$route.query.name">{{$route.query.name}}</span> -->
        <!-- </template> -->
        <el-menu-item-group>
          <el-menu-item index="BasicInfo" @click="handleClick('BasicInfo')" v-if="((isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.baseInfo">
            <i class="iconfont icon-icon_jbxx_off" aria-hidden="true"></i>
            <span>{{ $t('baseInfo') }}</span>
          </el-menu-item>
          <el-menu-item index="Dept" @click="handleClick('Dept')" v-if="((isOpen && isAdmin && isAdminDept ) || (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.department">
            <i class="iconfont icon-icon_bm_off" aria-hidden="true"></i>
            <span>{{ $t('department') }}</span>
          </el-menu-item>
          <el-menu-item index="User" @click="handleClick('User')" v-if="(!isOpen || (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || (isOpen && isSecret) || (isOpen && isAdmin && isAdminDept )) && setup.domain.user">
            <i class="iconfont icon-icon_yh_off" aria-hidden="true"></i>
            <span>{{ $t('user') }}</span>
          </el-menu-item>
          <el-menu-item index="Apps" @click="handleClick('Apps')" v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))   || !isOpen) && setup.domain.appconfig">
            <i class="iconfont icon-icon_rj_off" aria-hidden="true"></i>
            <span>{{ $t('appconfig') }}</span>
          </el-menu-item>
          <template v-if="!isOpen">
            <el-menu-item
              index="WeixinConfig"
              @click="handleClick('WeixinConfig')"
              v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.weixinConfig"
            >
            <i class="iconfont icon-icon_wxpz_off" aria-hidden="true"></i>
            <span>{{ $t('weixinConfig') }}</span>
            </el-menu-item>
          </template>
          <template v-if="!isOpen">
            <el-menu-item
              index="DingDingConfig"
              @click="handleClick('DingDingConfig')"
              v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.dingdingConfig"
            >
            <i class="iconfont icon-icon_ddpz" aria-hidden="true"></i>
            <span>{{ $t('dingdingConfig') }}</span>
            </el-menu-item>
          </template>
          <template v-if="!isOpen">
            <el-menu-item
              index="FeiShuConfig"
              @click="handleClick('FeiShuConfig')"
              v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))   || !isOpen) && setup.domain.feishuConfig"
            >
            <i class="iconfont icon-icon_fspz_off" aria-hidden="true"></i>
            <span>{{$t('feishuConfig')}}</span>
            </el-menu-item>
          </template>
          <!-- <el-menu-item index="Adns" @click="handleClick('Adns')">
            <i class="fa fa-user" aria-hidden="true"></i>
            <span class="marginL10">{{ $t('admin') }}</span>
          </el-menu-item> -->
          <el-menu-item index="WkCld" @click="handleClick('WkCld')" v-if="((isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))   || !isOpen) && setup.domain.calendar">
            <i class="iconfont icon-icon_gzrl_off" aria-hidden="true"></i>
            <span>{{ $t('calendar') }}</span>
          </el-menu-item>
          <el-menu-item
            index="UserFormExtends"
            @click="handleClick('UserFormExtends')"
            v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))   || !isOpen) && setup.domain.fieldextend"
          >
          <i class="iconfont icon-icon_zdkz_off" aria-hidden="true"></i>
          <span>{{ $t('fieldextend') }}</span>
          </el-menu-item>
          <el-menu-item index="Log" @click="handleClick('Log')" v-if="( !isOpen || (isOpen && isSecret) || (isOpen && isExamine)) && setup.domain.userlog">
            <i class="iconfont icon-icon_czrz_off" aria-hidden="true"></i>
            <span>{{ $t('userlog') }}</span>
          </el-menu-item>
          <el-menu-item
            index="FlowIntervention"
            @click="handleClick('FlowIntervention')"
            v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.flowstaterts"
          >
          <i class="iconfont icon-a-locate-outline1" aria-hidden="true"></i>
          <span>{{ $t('flowstaterts') }}</span>
          </el-menu-item>
          <el-menu-item index="Email" @click="handleClick('Email')" v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.emailconfig">
            <i class="iconfont icon-icon_yxsz_off" aria-hidden="true"></i>
            <span>{{ $t('emailconfig') }}</span>
          </el-menu-item>
          <el-menu-item index="TimedTask" @click="handleClick('TimedTask')" v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))   || !isOpen) && setup.domain.timedtask">
            <i class="iconfont icon-icon_dsrw_off" aria-hidden="true"></i>
            <span>{{ $t('timedtask') }}</span>
          </el-menu-item>
          <el-menu-item index="API" @click="handleClick('APIInterface')" v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))  || !isOpen) && setup.domain.openApi">
            <i class="iconfont icon-a-icon_OpenAPI_off" aria-hidden="true"></i>
            <span>Open API</span>
          </el-menu-item>
          <el-menu-item
            index="CloudConfig"
            @click="handleClick('CloudConfig')"
            v-if="( (isOpen && isAdmin && (isAdminDomain || isAdminDeptDomain))   || !isOpen) && setup.domain.cloudCapabilities"
          >
          <i class="iconfont icon-icon_ynl_off" aria-hidden="true"></i>
          <span>云能力</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
    <!-- 从前台登陆进来的时候显示 -->
    <el-menu :default-openeds="openeds" v-if="show == 'partMenu'">
      <el-submenu index="company">
        <template slot="title">
          <span>{{$route.query.name}}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="Dept" @click="handleClick('Dept')">
            <i class="fa fa-building-o" aria-hidden="true"></i>
            <span>{{ $t('department') }}</span>
          </el-menu-item>
          <el-menu-item index="User" @click="handleClick('User')">
            <i class="fa fa-user-o" aria-hidden="true"></i>
            <span>{{ $t('user') }}</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </el-scrollbar>
</template>

<script>
export default {
  name: 'menulist',
  data() {
    return {
      openeds: ['company'],
      isOpen:false,//开关是否开启
      isAdmin:false,//是否是系统管理员
      isAdminDept:false,//标识是否是部门及的系统管理员
      isAdminDomain:false,//标识是否是域级管理员
      isAdminDeptDomain:false,//标识是否是系统级管理员
      isSecret:false,//是否是安全保密员
      isExamine:false,//是否是安全审计员
      setup: setup,//菜单显示权限
    }
  },
  created(){
    if(this.$store.state.currentUser && this.$store.state.currentUser.isOpenSecurity) {
      this.isOpen=true;
      if (this.$store.state.currentUser.type == 'admin') {
        this.isAdmin = true;//是否是系统管理员
        if(this.$store.state.currentUser.domains.length>0 && this.$store.state.currentUser.departments.length<=0) this.isAdminDomain=true 
        if (this.$store.state.currentUser.departments.length <= 0 && this.$store.state.currentUser.domains.length <= 0) this.isAdminDeptDomain=true
        if (this.$store.state.currentUser.departments.length > 0 && this.$store.state.currentUser.domains.length > 0) {
          //部门及的系统管理员
          this.isAdminDept = true;
        }

      }else if(this.$store.state.currentUser.type == 'secret'){
        this.isSecret = true;//是否是安全保密员
      }
      else if(this.$store.state.currentUser.type == "examine"){
        this.isExamine = true;//是否是安全审计员
      }
    }else{
      this.isOpen=false;
    }
  },
  methods: {
    handleClick(val) {
      this.$emit('getActiveMenu', val)
    },
  },
  props:{
    show: String
  }
}
</script>